---所有资源根源点，根据配置生成在此处管理
---@class DataMapBase
---@field actionHandlerDic table<string,ActionHandlerBase> 标签和动作的键值
---@field goalsDic table<string, GoalBase>  标签和目标的键值
---@field triggerDic table<string,TriggerBase>  标签和触发器的键值
---@field agent AgentBase   代理
---@field gameData table<string,table>  该代理的数据存储
---@field base DataMapBase
DataMapBase = class()

---@param agent AgentBase
---@param onInitGameData function
function DataMapBase:ctor(agent)
    self.base = DataMapBase;
    self.agent = agent;
    self.actionHandlerDic = {}
    self.goalsDic = {}
    self.triggerDic = {}
    self.gameData = {}
    self:InitGameData();
    self:InitActionMaps();
    self:InitGoalMaps();
    self:InitTriggerMaps();
end
---初始化游戏数据 由子类实现
function DataMapBase:InitGameData() end
---初始化动作列表 由子类实现
function DataMapBase:InitActionMaps() end
---初始化目标列表 由子类实现
function DataMapBase:InitGoalMaps() end
---初始化触发器列表 由子类实现
function DataMapBase:InitTriggerMaps() end

---获取actionHandler
---@param label string
---@return ActionHandlerBase
function DataMapBase:GetActionHandler(label)
    local handler = self.actionHandlerDic[label];
    if handler == nil then
        Debug.LogError("actionHandler:"..label.."在DataMap中不存在")
    end
    return handler;
end

---获取目标Goal
---@param label string
---@return GoalBase
function DataMapBase:GetGoal(label)
    local goal = self.goalsDic[label];
    if goal == nil then
        Debug.LogError("Goal:"..label.."在DataMap中不存在")
    end
    return goal;
end

---获取触发器
---@param triggerType type
---@return TriggerBase
function DataMapBase:GetTrigger(triggerType)
    local trigger = self.triggerDic[triggerType];
    if trigger == nil then
        Debug.LogError("trigger:"..triggerType._className.."在DataMap中不存在")
    end
    return trigger;
end

---设置游戏数据
function DataMapBase:SetGameData(key, obj)
    self.gameData[key] = obj;
end

---获取游戏数据
function DataMapBase:GetGameData(key)
    return self.gameData[key];
end

---添加动作
---@param handlerType type
---@param actionType type
function DataMapBase:AddAction(handlerType, actionType,...)
    if handlerType == nil then
        Debug.LogError("往DataMap添加handler失败，传入的handlerType类型为nil")
    end
    if actionType == nil then
        Debug.LogError("往DataMap添加action失败，传入的actionType类型为nil")
    end
    ---@type ActionBase
    local action = GOAPObjPool:Spwan(actionType,self.agent,...)
    ---@type ActionHandlerBase
    local handler = GOAPObjPool:Spwan(handlerType,self.agent,self,action);
    if self.actionHandlerDic[handler.label] == nil then
        self.actionHandlerDic[handler.label] = handler;
    else
        Debug.LogError("发现具有重复标签的Handler,标签为："..handler.label);
    end
end

function DataMapBase:AddGoal(goalType)
    if goalType == nil then
        Debug.LogError("往DataMap添加Goal失败，传入的Goal类型为nil")
    end
    ---@type GoalBase
    local goal = GOAPObjPool:Spwan(goalType,self.agent);
    if self.goalsDic[goal.label] == nil then
        self.goalsDic[goal.label] = goal;
    else
        Debug.LogError("发现具有相同目标的Goal,标签为："..goal.label);
    end
end

function DataMapBase:AddTrigger(triggerType)
    if triggerType == nil then
        Debug.LogError("往DataMap添加trigger失败，传入的trigger类型为nil")
    end
    ---@type TriggerBase
    local trigger = GOAPObjPool:Spwan(triggerType,self.agent);
    if self.triggerDic[triggerType] == nil then
        self.triggerDic[triggerType] = trigger;
    else
        Debug.LogError("重复添加触发器："..triggerType._className)
    end
end